package controllers

import (
	"ginDev/frans"
	"ginDev/models"
	"github.com/gin-gonic/gin"
	"log"
)

//新版本
type UserController struct {
	///*goft.GormAdapter

	*frans.GormAdapter
}

func NewUserController() *UserController {
	return &UserController{}
}

/*func (this *UserController) Index() gin.HandlerFunc {
	return func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{
			"data": "user index",
		})
	}
}

func (this *UserController) UserList() gin.HandlerFunc {
	return func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{
			"data": "user list ",
		})
	}
}

func (this *UserController) UserDetail() gin.HandlerFunc {

	return func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{
			"data": "user detail ",
		})
	}
}

func (this *UserController) Route(frans *frans.Frans) {
	frans.Handle("GET", "/user", this.Index()).
		GET("/userlist", this.UserList()).
		GET("/userinfo", this.UserDetail())
}*/

func (this *UserController) Index(ctx *gin.Context) string {
	return " user index "
}

func (this *UserController) UserList(ctx *gin.Context) []models.UserModel {
	return []models.UserModel{
		{Id: 1, Username: "frans", Password: "zxczxc"},
		{Id: 1, Username: "frans", Password: "zxczxc"},
	}
}

func (this *UserController) UserDetail(ctx *gin.Context) frans.Model {

	var user = models.UserModel{}

	this.Table("users").Where("id=?", 2).Find(&user)
	log.Println(user)

	return &user
}

func (this *UserController) Route(frans *frans.Frans) {
	frans.Handle("GET", "/user", this.Index).
	Handle("GET", "/userlist", this.UserList).
	Handle("GET", "/userinfo", this.UserDetail)
}
